#include "bufferobject.h"

BufferObject::BufferObject (GLenum target, bool bindToDefaultVAO) {
    // !!! binging can cause error if trying
    // to bing without binded VAO
    // Bind empty vertex array object
    // If no VAO binded is not working correcly
    if (bindToDefaultVAO) {
        glBindVertexArray(0);    
    }
    
    this->target = target;
    this->generate();
    this->bind();
}

BufferObject::~BufferObject () {}

GLuint BufferObject::getID () {
    return this->id;
}

void BufferObject::generate () {
    glGenBuffers(1, &this->id);
}

void BufferObject::bind () {
    glBindBuffer(this->target, this->id);
}

void BufferObject::setData (GLsizeiptr size, const GLvoid *data, GLenum usage) {
    
    glBufferData(this->target, size, data, usage);
}